package 力扣;

import java.util.ArrayList;

/**
 * @author yyq
 * @create 2022-06-02 15:30
 */
public class leetcode376 {
    public static void main(String[] args) {
        leetcode376 leetcode376=new leetcode376();
        System.out.println(leetcode376.wiggleMaxLength(new int[]{3,3,3,2,5}));
    }
    ArrayList<Integer> list=new ArrayList<>();
    int maxLength = 0;
    public int wiggleMaxLength(int[] nums) {
        int tempL = 0;
        if(nums.length==1) return 1;
        int[] temp=new int[nums.length-1];
        boolean flag=true;
        for(int i=1;i<nums.length;i++){
            if(flag&&nums[i]==nums[i-1]) {
                flag=true;
                continue;
            }
            else flag=false;
            temp[tempL] = nums[i] - nums[i-1];
            tempL++;
        }
        if(flag) return 1;
        list.add(temp[0]);
        int startIndex=1;
        backTracking(temp,startIndex,tempL);
        return maxLength+1;
    }

    private void backTracking(int[] temp, int startIndex,int tempL) {
        if(list.size()>maxLength) maxLength=list.size();
        for (int i = startIndex;i<tempL;i++){
            if(maxLength==tempL) return;
            if((list.get(list.size()-1)>0&&temp[i]<0)||(list.get(list.size()-1)<0&&temp[i]>0)){
                list.add(temp[i]);
                backTracking(temp,i+1,tempL);
                list.remove(list.size()-1);
            }
        }
    }
}
